package com.eqdd.yiqidian.ui.companyspace

import android.app.Activity
import android.app.AlertDialog
import android.content.Intent
import android.graphics.Bitmap
import android.graphics.Color
import android.graphics.drawable.BitmapDrawable
import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.text.SpannableString
import android.text.Spanned
import android.text.style.ForegroundColorSpan
import android.view.View
import android.widget.ImageView
import com.bumptech.glide.Glide
import com.bumptech.glide.request.target.SimpleTarget
import com.bumptech.glide.request.transition.Transition
import com.eqdd.yiqidian.R
import com.eqdd.yiqidian.adapter.MyFragmentPagerAdapter
import com.eqdd.yiqidian.adapter.recycleadapter.ItemClickSupport
import com.eqdd.yiqidian.adapter.slimadapter.SlimAdapterEx
import com.eqdd.yiqidian.adapter.slimadapter.SlimInjector
import com.eqdd.yiqidian.base.AppConstent
import com.eqdd.yiqidian.base.BaseActivity
import com.eqdd.yiqidian.base.Config
import com.eqdd.yiqidian.bean.LeaveMessageBean
import com.eqdd.yiqidian.bean.PayFunctionBean
import com.eqdd.yiqidian.bean.ProductBean
import com.eqdd.yiqidian.bean.SpaceVisitorBean
import com.eqdd.yiqidian.box.ItemDecoration.DividerLineItemDecoration
import com.eqdd.yiqidian.helper.mvchelper.ModelRx2DataSource
import com.eqdd.yiqidian.http.DialogCallBack
import com.eqdd.yiqidian.http.HttpConfig
import com.eqdd.yiqidian.http.HttpResult
import com.eqdd.yiqidian.http.JsonConverter
import com.eqdd.yiqidian.kotlin.BaseRecyclerViewAdapter
import com.eqdd.yiqidian.kotlin.imgPathPreview
import com.eqdd.yiqidian.kotlin.toArrayList
import com.eqdd.yiqidian.ui.InputDialogActivity
import com.eqdd.yiqidian.ui.mine.UserCardActivity
import com.eqdd.yiqidian.ui.yiqigou.ShoppingMainActivity
import com.eqdd.yiqidian.ui.yiqiyue.AddArticleActivity
import com.eqdd.yiqidian.utils.ImageUtil
import com.eqdd.yiqidian.utils.TimeUtil
import com.eqdd.yiqidian.utils.ToastUtil
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.lzy.okgo.OkGo
import com.lzy.okgo.model.Response
import com.lzy.okrx2.adapter.FlowableBody
import com.shizhefei.mvc.MVCCoolHelper
import io.reactivex.Flowable
import kotlinx.android.synthetic.main.activity_company_space.*
import kotlinx.android.synthetic.main.list_item_150.view.*
import org.jetbrains.anko.sdk25.coroutines.onClick
import org.jetbrains.anko.startActivity
import org.jetbrains.anko.startActivityForResult
import org.jetbrains.anko.toast
import java.io.Serializable
import java.util.*

/**
 * 企业空间
 * Created by jhj on 18-6-23.
 */
class CompanySpaceActivity : BaseActivity() {

    companion object {
        const val ACTION_PAY_FUNCTION = 1000
        const val ACTION_PRODUCT = 1001
        const val TYPE_DIARY = "type_diary"
        const val TYPE_INFO = "type_info"
        const val TYPE_DEMAND = "type_demand"
        const val TYPE_CULTURE = "type_culture"

        const val diary = "写日志,我的日志"
        const val info = "公司简介,基本信息,设备展示,组织机构,团队介绍,联系我们"
        const val culture = "核心价值观,领导活动,先进事迹,荣誉墙"
        const val demand = "发布的需求,匹配的需求,易企购"

        const val leftStr = """
                            [
                                {"id":"1","label":"日志"},
                                {"id":"2","label":"产品信息"},
                                {"id":"3","label":"企业信息"},
                                {"id":"4","label":"企业文化"},
                                {"id":"5","label":"留言"},
                                {"id":"6","label":"访客"},
                                {"id":"7","label":"交易记录"},
                                {"id":"8","label":"企业需求"},
                                {"id":"9","label":"付费功能"},
                                {"id":"10","label":"我的收藏"}
                            ]
                            """


    }


    private var dataList: List<LeftItemBean>? = null
    private var adapter: CompanySpaceAdapter? = null
    private var deleteBean: LeaveMessageBean? = null
    private var clickMessageBean: LeaveMessageBean? = null

    private var isFirst2Product: Boolean = true
    private var isFirst2Message: Boolean = true
    private var isFirst2Pay: Boolean = true
    private var isFirst2Visitor: Boolean = true
    private var productMvcHelper: MVCCoolHelper<List<ProductBean>>? = null
    private var messageMvcHelper: MVCCoolHelper<List<LeaveMessageBean>>? = null
    private var payMvcHelper: MVCCoolHelper<List<PayFunctionBean>>? = null
    private var visitorMvcHelper: MVCCoolHelper<List<SpaceVisitorBean>>? = null


    override fun initBinding() {
        setContentView(R.layout.activity_company_space)
        initTopTitleBar(View.VISIBLE, "企业空间")
    }

    override fun initData() {
        //左侧导航栏
        dataList = Gson().fromJson<List<LeftItemBean>>(leftStr, object : TypeToken<List<LeftItemBean>>() {}.type)

        recycler_left.layoutManager = LinearLayoutManager(this)
        adapter = CompanySpaceAdapter(this)
        adapter?.dataList = dataList as ArrayList<LeftItemBean>
        recycler_left.adapter = adapter

        //右侧菜单栏
        recycler_right.addItemDecoration(DividerLineItemDecoration(this))
        recycler_right.layoutManager = LinearLayoutManager(this)

        resetView(1)
        dataList?.get(0)?.isChecked = true
        refreshList(diary, TYPE_DIARY)
    }

    override fun setView() {

    }


    fun leftItemOnClick(bean: LeftItemBean) {
        refreshRight(bean)
        bean.isChecked = !bean.isChecked
        dataList?.forEach {
            if (it.label != bean.label) {
                it.isChecked = false
            }
        }
        adapter?.notifyDataSetChanged()
    }

    fun resetView(type: Int) {
        coolRefreshView1.visibility = View.GONE
        coolRefreshView2.visibility = View.GONE
        coolRefreshView3.visibility = View.GONE
        coolRefreshView4.visibility = View.GONE
        recycler_right.visibility = View.GONE
        recycler_right.removeAllViews()
        relativeLayout.visibility = View.GONE
        relativeLayout1.visibility = View.GONE
        productMvcHelper?.loadView?.restore()
        messageMvcHelper?.loadView?.restore()
        visitorMvcHelper?.loadView?.restore()
        payMvcHelper?.loadView?.restore()
        when (type) {
            1 -> recycler_right.visibility = View.VISIBLE
            2 -> coolRefreshView1.visibility = View.VISIBLE
            3 -> recycler_right.visibility = View.VISIBLE
            4 -> recycler_right.visibility = View.VISIBLE
            5 -> coolRefreshView2.visibility = View.VISIBLE
            6 -> coolRefreshView3.visibility = View.VISIBLE
            7 -> relativeLayout.visibility = View.VISIBLE
            8 -> recycler_right.visibility = View.VISIBLE
            9 -> coolRefreshView4.visibility = View.VISIBLE
            10 -> relativeLayout1.visibility = View.VISIBLE
        }
    }

    private fun refreshRight(bean: LeftItemBean) {
        when (bean.id) {
            1 -> {
                resetView(1)
                refreshList(diary, TYPE_DIARY)
            }
            2 -> {
                resetView(2)
                if (isFirst2Product) {
                    productList()
                } else {
                    productMvcHelper?.refresh()
                }
            }
            3 -> {
                resetView(3)
                refreshList(info, TYPE_INFO)
            }
            4 -> {
                resetView(4)
                refreshList(culture, TYPE_CULTURE)
            }
            5 -> {
                resetView(5)
                if (isFirst2Message) {
                    leaveMessage()
                } else {
                    messageMvcHelper?.refresh()
                }
            }
            6 -> {
                resetView(6)
                if (isFirst2Visitor) {
                    spaceVisitor()
                } else {
                    visitorMvcHelper?.refresh()
                }
            }
            7 -> {
                resetView(7)
                transactionRecord()
            }
            8 -> {
                resetView(8)
                refreshList(demand, TYPE_DEMAND)
            }
            9 -> {
                resetView(9)
                if (isFirst2Pay) {
                    payRequest()
                } else {
                    payMvcHelper?.refresh()
                }
            }
            10 -> {
                resetView(10)
                collect()
            }

        }
    }


    private fun refreshList(str: String, type: String) {
        val adapter = ListAdapter(type)
        adapter.dataList = str.split(",").toList().toArrayList()
        recycler_right.adapter = adapter
    }


    private fun productList() {
        var pageNum = 0
        val list = arrayListOf<ProductBean>()
        isFirst2Product = false
        recyclerView1.layoutManager = LinearLayoutManager(this)
        recyclerView1.addItemDecoration(DividerLineItemDecoration(this))
        val slimAdapterEx = SlimAdapterEx.create().register<ProductBean>(R.layout.list_item_166, SlimInjector<ProductBean> { data, injector ->
            val str = String.format(Locale.CHINA, "产品价格：￥%s元", data?.productPrice)
            val span = SpannableString(str)
            span.setSpan(ForegroundColorSpan(Color.RED), 5, str.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
            injector
                    ?.with<ImageView>(R.id.iv_image) { view ->
                        if (data?.image?.isNotBlank() == true) {
                            view.visibility = View.VISIBLE
                            view.onClick {
                                imgPathPreview(data.image)
                            }
                            Glide.with(this)
                                    .asBitmap()
                                    .apply(ImageUtil.optionsNormal)
                                    .load(data.image)
                                    .into(object : SimpleTarget<Bitmap>() {
                                        override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>) {
                                            val scale = resource.width.toDouble() / resource.height.toDouble()
                                            if (scale < 0.85 && scale > 0.65) {
                                                view.scaleType = ImageView.ScaleType.CENTER_CROP
                                            }
                                            view.background = BitmapDrawable(resources, resource)
                                        }
                                    })
                        } else {
                            view.visibility = View.GONE
                        }
                    }
                    ?.text(R.id.tv_name, String.format(Locale.CHINA, "产品名称：%s", data?.productName))
                    ?.text(R.id.tv_post, span)
                    ?.text(R.id.tv_msg, String.format(Locale.CHINA, "发货地址：%s", data?.area))
                    ?.text(R.id.tv_label, data?.productType)
        }).attachTo(recyclerView1).updateData(list as List<ProductBean>?) as SlimAdapterEx<ProductBean>?
        ItemClickSupport.addTo(recyclerView1).setOnItemClickListener { recyclerView, position, v ->
            if (slimAdapterEx?.getDataItem(position) != null) {
                startActivityForResult<ProductInfoActivity>(ACTION_PRODUCT, Config.ID to slimAdapterEx.getDataItem(position)?.id
                        , Config.TYPE to 1)
            }
        }
        productMvcHelper = MVCCoolHelper<List<ProductBean>>(coolRefreshView1)


        val dataSource = ModelRx2DataSource<ProductBean>(ModelRx2DataSource.OnLoadSource<ProductBean> { page, register ->
            pageNum = if (page == 1) 0 else pageNum
            OkGo.post<HttpResult<List<ProductBean>>>(HttpConfig.BASE_URL + HttpConfig.PRODUCT_LIST)
                    .params("companyId", user.companyId)
                    .params("page", pageNum)
                    .converter(object : JsonConverter<HttpResult<List<ProductBean>>>() {
                        override fun test() {
                            super.test()
                        }
                    }).adapt(FlowableBody<HttpResult<List<ProductBean>>>())
                    .flatMap({ result ->
                        if (page == 1) {
                            productMvcHelper?.setAutoLoadMore(true)
                        }
                        pageNum = result.page
                        Flowable.just<MutableList<ProductBean>>(if (result.items == null) ArrayList() else result.items as MutableList<ProductBean>?)
                    })
        }, 10)


        productMvcHelper?.setDataSource(dataSource)
        productMvcHelper?.adapter = slimAdapterEx
        productMvcHelper?.refresh()
    }


    private fun leaveMessage() {
        var messagePageNum = 0
        val list = arrayListOf<LeaveMessageBean>()
        isFirst2Message = false
        messageMvcHelper = MVCCoolHelper<List<LeaveMessageBean>>(coolRefreshView2)
        recyclerView2.layoutManager = LinearLayoutManager(this)
        recyclerView2.addItemDecoration(DividerLineItemDecoration(this))
        val slimAdapterEx = SlimAdapterEx.create().register<LeaveMessageBean>(R.layout.list_item_156, SlimInjector<LeaveMessageBean> { data, injector ->
            injector?.text(R.id.tv_name, data?.staffName)
                    ?.text(R.id.tv_depart, String.format(Locale.CHINA, "%s - %s", data?.departName, data?.postName))
                    ?.text(R.id.tv_time, TimeUtil.formatWebTime(data?.createTime))
                    ?.imageCircle(R.id.iv_photo, data?.iphoto)
                    ?.text(R.id.tv_message, data?.message)
                    ?.clicked(R.id.iv_photo) {
                        startActivity<UserCardActivity>(Config.GUID to data?.creater)
                    }
                    ?.with<RecyclerView>(R.id.recyclerView) { recyclerView ->
                        recyclerView.layoutManager = LinearLayoutManager(this)
                        data?.childList?.let {
                            SlimAdapterEx.create().register<LeaveMessageBean>(R.layout.list_item_162, SlimInjector<LeaveMessageBean> { t1, t2 ->
                                val span = SpannableString("企业回复：" + t1?.message)
                                span.setSpan(ForegroundColorSpan(Color.GRAY), 0, 5, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
                                t2
                                        ?.gone(R.id.tv_label)
                                        ?.text(R.id.tv_reply, span)
                                        ?.longClicked(R.id.tv_label) {
                                            deleteBean = t1
                                            deleteComment() {
                                                messageMvcHelper?.refresh()
                                            }
                                            false
                                        }
                            }).attachTo(recyclerView).updateData(it.toArrayList() as List<LeaveMessageBean>)
                        }

                    }
                    ?.clicked(R.id.tv_message) {
                        clickMessageBean = data
                        startActivityForResult<InputDialogActivity>(Config.INPUT, Config.TALK_TO to clickMessageBean?.upname)
                    }
        }).attachTo(recyclerView2).updateData(list as List<LeaveMessageBean>?) as SlimAdapterEx<LeaveMessageBean>?
        ItemClickSupport.addTo(recyclerView2).setOnItemClickListener { recyclerView, position, v ->

        }
        val dataSource = ModelRx2DataSource<LeaveMessageBean>(ModelRx2DataSource.OnLoadSource<LeaveMessageBean> { page, register ->
            if (page == 1) {
                messagePageNum = 0
            }
            OkGo.post<HttpResult<List<LeaveMessageBean>>>(HttpConfig.BASE_URL + HttpConfig.LEAVE_MESSAGE_LIST)
                    .params("companyId", user.companyId)
                    .params("page", messagePageNum)
                    .converter(object : JsonConverter<HttpResult<List<LeaveMessageBean>>>() {
                        override fun test() {
                            super.test()
                        }
                    }).adapt(FlowableBody<HttpResult<List<LeaveMessageBean>>>())
                    .flatMap({ result ->
                        if (page == 1) {
                            messageMvcHelper?.isAutoLoadMore = true
                        }
                        messagePageNum = result.page
                        Flowable.just<MutableList<LeaveMessageBean>>(if (result.items == null) ArrayList() else result.items as MutableList<LeaveMessageBean>?)
                    })
        }, 10)


        messageMvcHelper?.setDataSource(dataSource)
        messageMvcHelper?.adapter = slimAdapterEx
        messageMvcHelper?.refresh()
    }

    private fun deleteComment(function: () -> Unit) {

        AlertDialog.Builder(this)
                .setTitle("提示")
                .setMessage("是否删除${"“${deleteBean?.message ?: "该数据"}”?"}")
                .setPositiveButton("取消", null)
                .setNegativeButton("确定", { _, _ ->
                    OkGo.post<HttpResult<*>>(HttpConfig.BASE_URL + HttpConfig.LEAVE_MESSAGE_DELETE)
                            .params("userGuid", AppConstent.user.guid)
                            .params("companyId", user.companyId)
                            .params("msgId", deleteBean?.id ?: 0)
                            .params("type", 2)
                            .execute(object : DialogCallBack<HttpResult<*>>(this) {
                                override fun onSuccess(response: Response<HttpResult<*>>) {
                                    val httpResult = response.body()
                                    ToastUtil.showShort(httpResult.msg)
                                    if (httpResult.status == 200) {
                                        function()
                                        messageMvcHelper?.refresh()
                                    } else {
                                        toast("删除失败")
                                    }
                                }
                            })
                })
                .show()


    }


    private fun responseMessage(msg: String) {
        OkGo.post<HttpResult<LeaveMessageBean>>(HttpConfig.BASE_URL + HttpConfig.LEAVE_MESSAGE_ADD)
                .params("userGuid", user.guid)
                .params("userCompanyId", user.companyId)
                .params("message", msg)
                .params("companyId", clickMessageBean?.companyId ?: 0)
                .params("parentId", clickMessageBean?.id ?: 0)
                .params("parentUserGuid", clickMessageBean?.creater)
                .params("firstCommentId", clickMessageBean?.id ?: 0)
                .execute(object : DialogCallBack<HttpResult<LeaveMessageBean>>(this) {
                    override fun onSuccess(response: Response<HttpResult<LeaveMessageBean>>?) {
                        val result = response?.body()
                        if (result?.status == 200) {
                            messageMvcHelper?.refresh()
                        } else {
                            toast(result?.msg ?: "")
                        }
                    }

                })
    }


    private fun spaceVisitor() {
        var visitorPageNum = 0
        val list = arrayListOf<SpaceVisitorBean>()
        isFirst2Visitor = false
        visitorMvcHelper = MVCCoolHelper<List<SpaceVisitorBean>>(coolRefreshView3)
        recyclerView3.layoutManager = LinearLayoutManager(this)
        recyclerView3.addItemDecoration(DividerLineItemDecoration(this))
        val slimAdapterEx = SlimAdapterEx.create().register<SpaceVisitorBean>(R.layout.list_item_155, SlimInjector<SpaceVisitorBean> { data, injector ->
            injector?.text(R.id.tv_name, data?.staffName)
                    ?.text(R.id.tv_depart, String.format(Locale.CHINA, "%s - %s", data?.departName, data?.postName))
                    ?.text(R.id.tv_time, TimeUtil.formatWebTime(data?.createTime))
                    ?.text(R.id.tv_preview, data?.useroption)
                    ?.imageCircle(R.id.iv_photo, HttpConfig.BASE_URL + data?.iphoto)
                    ?.clicked(R.id.iv_photo) {
                        startActivity<UserCardActivity>(Config.GUID to data?.creater)
                    }
        }).attachTo(recyclerView3).updateData(list as List<SpaceVisitorBean>?) as SlimAdapterEx<SpaceVisitorBean>?
        ItemClickSupport.addTo(recyclerView3).setOnItemClickListener { recyclerView, position, v ->

        }
        val dataSource = ModelRx2DataSource<SpaceVisitorBean>(ModelRx2DataSource.OnLoadSource<SpaceVisitorBean> { page, register ->
            if (page == 1) {
                visitorPageNum = 0
            }
            OkGo.post<HttpResult<List<SpaceVisitorBean>>>(HttpConfig.BASE_URL + HttpConfig.SPACE_VISITOR_LIST)
                    .params("companyId", user.companyId)
                    .params("page", visitorPageNum)
                    .converter(object : JsonConverter<HttpResult<List<SpaceVisitorBean>>>() {
                        override fun test() {
                            super.test()
                        }
                    }).adapt(FlowableBody<HttpResult<List<SpaceVisitorBean>>>())
                    .flatMap({ result ->
                        if (page == 1) {
                            visitorMvcHelper?.isAutoLoadMore = true
                        }
                        visitorPageNum = result.page
                        Flowable.just<MutableList<SpaceVisitorBean>>(if (result.items == null) ArrayList() else result.items as MutableList<SpaceVisitorBean>?)
                    })
        }, 10)

        visitorMvcHelper?.setDataSource(dataSource)
        visitorMvcHelper?.adapter = slimAdapterEx
        visitorMvcHelper?.refresh()
    }


    private fun payRequest() {
        var pageNum = 0
        val list = arrayListOf<PayFunctionBean>()
        isFirst2Pay = false
        payMvcHelper = MVCCoolHelper<List<PayFunctionBean>>(coolRefreshView4)
        recyclerView4.layoutManager = LinearLayoutManager(this)
        recyclerView4.addItemDecoration(DividerLineItemDecoration(this))
        val slimAdapterEx = SlimAdapterEx.create().register<PayFunctionBean>(R.layout.list_item_150, SlimInjector<PayFunctionBean> { data, injector ->
            injector?.text(R.id.tv_content, data?.modularName)
        }).attachTo(recyclerView4).updateData(list as List<PayFunctionBean>?) as SlimAdapterEx<PayFunctionBean>?
        ItemClickSupport.addTo(recyclerView4).setOnItemClickListener { recyclerView, position, v ->
            startActivityForResult<PayFunctionActivity>(ACTION_PAY_FUNCTION, "data" to slimAdapterEx?.getDataItem(position))
        }

        val dataSource = ModelRx2DataSource<PayFunctionBean>(ModelRx2DataSource.OnLoadSource<PayFunctionBean> { page, register ->
            if (page == 1) {
                pageNum = 0
            }

            OkGo.post<HttpResult<List<PayFunctionBean>>>(HttpConfig.BASE_URL + HttpConfig.PAY_FUN)
                    .params("companyId", user.companyId)
                    .params("page", pageNum)
                    .converter(object : JsonConverter<HttpResult<List<PayFunctionBean>>>() {
                        override fun test() {
                            super.test()
                        }
                    }).adapt(FlowableBody<HttpResult<List<PayFunctionBean>>>())
                    .flatMap({ result ->
                        if (page == 1) {
                            payMvcHelper?.isAutoLoadMore = true
                        }
                        pageNum = result.page
                        Flowable.just<MutableList<PayFunctionBean>>(if (result.items == null) ArrayList() else result.items as MutableList<PayFunctionBean>?)
                    })
        }, 10)
        payMvcHelper?.setDataSource(dataSource)
        payMvcHelper?.adapter = slimAdapterEx
        payMvcHelper?.refresh()

    }

    private fun transactionRecord() {
        val list = arrayListOf<String>("全部订单", "未付款", "已付款")
        val fragment = arrayListOf<Fragment>(getRecordFragment(0), getRecordFragment(-2), getRecordFragment(1))
        // 第二步：为ViewPager设置适配器
        view_pager.adapter = MyFragmentPagerAdapter(supportFragmentManager, list, fragment)
        //  第三步：将ViewPager与TableLayout 绑定在一起
        tab_layout.setupWithViewPager(view_pager)

    }

    private fun getRecordFragment(status: Int): Fragment {
        val fragment = TransactionRecordFragment()
        val bundle = Bundle()
        bundle.putInt(Config.COMPANY_ID, user.companyId)
        bundle.putInt(Config.STATUS, status)
        fragment.arguments = bundle
        return fragment
    }

    private fun collect() {
        val list = arrayListOf<String>("企业收藏", "产品收藏")
        val fragment = arrayListOf<Fragment>(getCollectFragment(0), getCollectFragment(1))
        // 第二步：为ViewPager设置适配器
        view_pager1.adapter = MyFragmentPagerAdapter(supportFragmentManager, list, fragment)
        //  第三步：将ViewPager与TableLayout 绑定在一起
        tab_layout1.setupWithViewPager(view_pager1)

    }

    private fun getCollectFragment(status: Int): Fragment {
        val fragment = CollectionFragment()
        val bundle = Bundle()
        bundle.putInt(Config.COMPANY_ID, user.companyId)
        bundle.putInt(Config.STATUS, status)
        bundle.putString(Config.ID, user.guid)
        fragment.arguments = bundle
        return fragment
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (resultCode == Config.SUCCESS) {
            when (requestCode) {
                Config.INPUT -> {
                    val str = data?.getStringExtra(Config.CONTENT)
                    responseMessage(str ?: "")
                }
            }
        }

        if (resultCode == Activity.RESULT_OK) {
            when (requestCode) {
                ACTION_PRODUCT -> productMvcHelper?.refresh()
            }
        }

    }

    inner class ListAdapter(val type: String) : BaseRecyclerViewAdapter<String>() {
        override fun onCreateView(viewType: Int): Int {
            return R.layout.list_item_150
        }

        override fun onBindViewItemViewHolder(holder: ItemViewHolder, bean: String, position: Int) {
            holder.itemView?.let {
                it.tv_content.text = bean
                it.onClick {
                    if (type == TYPE_DIARY) {
                        when (position) {
                            0 -> startActivity<AddArticleActivity>("source" to 1)
                            1 -> startActivity<CompanyDiaryListActivity>()
                        }
                    } else if (type == TYPE_INFO) {
                        when (position) {
                            0 -> startActivity<CompanyIntroduceActivity>()
                            1 -> startActivity<CompanyInfoActivity>()
                            2 -> startActivity<EquipmentListActivity>()
                            3 -> startActivity<OrganizationListActivity>()
                            4 -> startActivity<TeamMemberListActivity>()
                            5 -> startActivity<ContactWayInfoActivity>()
                        }

                    } else if (type == TYPE_CULTURE) {
                        when (position) {
                            0 -> startActivity<CoreValueListActivity>()
                            1 -> startActivity<LeaderMovableListActivity>()
                            2 -> startActivity<AdvancedEventListActivity>()
                            3 -> startActivity<ExcellentStaffListActivity>()
                        }

                    } else if (type == TYPE_DEMAND) {
                        when (position) {
                            0 -> startActivity<DemandListActivity>(Config.TYPE to 0)
                            1 -> startActivity<DemandListActivity>(Config.TYPE to 1)
                            2 -> startActivity<ShoppingMainActivity>()
                        }
                    }
                }
            }
        }
    }


    class LeftItemBean(
            val id: Int = 0,
            val label: String = "",
            var isChecked: Boolean = false
    ) : Serializable

}
